<template>
  <div class="docker">
      <div class="function-bar">
      <el-button
        size="mini"
        class="bar-search-item"
        type="primary"
        icon="el-icon-refresh"
        @click="handleRefresh"
      >刷新</el-button>
      <el-input
        v-model="searchNick"
        class="bar-search-item-input"
        size="mini"
        placeholder="请输入昵称"
      >
        <template slot="prepend">用户昵称</template>
      </el-input>
      <el-button
        size="mini"
        class="bar-search-item"
        type="primary"
        icon="el-icon-search"
        @click="handleSelect"
      >筛选</el-button>
    </div>
      <el-table
        :data="this.RankList"
        tooltip-effect="dark"
        highlight-current-row
        v-loading="loading"
        border
        :cell-class-name="changeTrStyle"
      >
        <el-table-column
          label="排名"
          width="150"
          align="center"
        >
        <template slot-scope="scope">
          {{scope.$index+1}}
          </template>
        </el-table-column>
        <el-table-column
          label="昵称"
        >
        <template slot-scope="scope">
          <el-link
            type="primary"
            @click="toUser(scope.row.username)"
          >{{scope.row.nickname}}</el-link>
        </template>
        </el-table-column>
        <el-table-column
        prop="acnumber"
          label="通过题数"
          width="100"
          align="center"
        >
        </el-table-column>
        <el-table-column
        prop="wrongnumber"
          label="错误次数"
          width="100"
          align="center"
        >
        </el-table-column>
        <el-table-column :label= "String.fromCharCode(item.problemOrder + 65)"
        width="100"
        align= "center"
        v-for="item in ProblemList"
                   :key="item"
        >
        <template slot-scope="scope">
        <div  v-for="items in problemstatus" :key="items" style=""
            >
            <div v-if="items.problemId == item.problemId && items.username == scope.row.username && items.isSloved==1 && items.wrongNumber != 0"
            >
            -{{items.wrongNumber}}
            </div>
            <div v-else-if="items.problemId == item.problemId && items.username == scope.row.username && items.isSloved==0 "
            >
            -{{items.wrongNumber}}
            </div>
            <div v-else-if="items.problemId == item.problemId && items.username == scope.row.username && items.isSloved==1 && items.wrongNumber == 0"
            >
            </div>
            </div>
        </template>
        </el-table-column>
      </el-table>
  </div>
</template>
<script>
export default {
  props: {
    cid: String,
    contestInfo: Object,
    ProblemList: []
  },
  data () {
    return {
      RankList: [],
      problemstatus: [],
      isSearch: false,
      loading: false
    }
  },
  mounted () {
    this.getProblemstatus()
  },
  methods: {
    async getProblemstatus () {
      this.contestId = String(this.$route.query.cid)
      let params = new URLSearchParams()
      params.append('contestId', this.contestId)
      let RankList = await this.$http
        .get('/contest/rank', params)
        .catch(() => {
        })
      console.log(RankList)
      this.problemstatus = RankList.datas[1]
      this.RankList = RankList.datas[0]
    },
    toUser (val) {
      this.$router.push({ path: '/User', query: { username: val } })
      console.log(val)
    },
    // 修改表格背景色
    changeTrStyle ({ row, column, rowIndex, columnIndex }) {
      if (column.label !== '排名' && column.label !== '昵称' && column.label !== '通过题数' && column.label !== '错误次数') {
        let i
        for (i = 0; i < this.problemstatus.length; i++) {
          if (this.RankList[rowIndex].username === this.problemstatus[i].username && this.problemstatus[i].problemId === this.ProblemList[columnIndex - 4].problemId) {
            if (this.problemstatus[i].isSloved === 1) {
              return 'isAC'
            } else if (this.problemstatus[i].isSloved === 0) {
              return 'isWrong'
            }
          }
        }
      }
    },
    handleRefresh () {
      this.loading = true
      this.getProblemstatus()
      this.loading = false
    }

  }

}
</script>
<style >
.docker {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 700px;
}

.box-card {
  width: 100%;
  height: 100%;
  min-height: 500px;
  display: block;
  margin-left: auto;
  margin-right: auto;
  padding: 0;
  margin-top: 0%;
  margin-bottom: 0%;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: '';
}

.clearfix:after {
  clear: both;
}

.functionBar {
  width: 100%;
  margin: 0;
  padding: 0;
  height: 50px;
  border-bottom: 1px solid silver;
}

.function-bar {
  width: 100%;
  height: 40px;
  border-bottom: 1px solid #eeeeee;
}

.bar-search-item-input {
  float: left;
  width: 15%;
  margin-right: 20px;
}

.bar-search-item-select {
  float: left;
  width: 15%;
  margin-right: 20px;
}

.bar-search-item {
  float: left;
  /* width: 15%; */
  margin-right: 20px;
}

.search-button {
  float: left;
}
.pagination {
  float: left;
  margin-left: 10px;
  height: 30px;
  margin-top: 10px;
}

.input {
  float: right;
  margin-right: 10px;
  margin-top: 10px;
  height: 30px;
  width: 200px;
}
.el-table tr td.developing{
  background: #FFE4B5;
  opacity:0.9;
}
.el-table tr td.testing{
  background: #FFA500;
  opacity:0.9;
}
.el-table tr td.isWrong{
  background: #f7423c;
  opacity:0.9;
}
.el-table tr td.isAC{
  background: #9ACD32;
  opacity:0.9;
}
</style>
